<?PHP
if (!session_start()) { session_start(); };
/*if (!isset($_SESSION['lgnapproved'])) {
	die(header('Location: login.php'));
}*/

include("functions.php");
include("cnnxn.php");
connect();

if (isset($_POST['submit'])) {

	$dateadded=date("Y-m-d");
	$combineddate=$_POST['eventdate_year'].'-'.$_POST['eventdate_month'].'-'.$_POST['eventdate_day'];
	
	$fieldnames="";
	$tempvalue="";
	$modstring="";
	while (list($key,$value) = each($_POST)) {
	if ($value!='modify') {
		if (ctype_digit($value)) {
		   $tempvalue=$value;
		} else {
		   $tempvalue='"'.addslashes($value).'"';
		}
		$modstring=$modstring.$key.'='.$tempvalue.',';
	}
	}
	
	
	$fieldnames=substr_replace($fieldnames,"",-8);
	$modstring=substr_replace($modstring,"",-1);
	print $SQLmod='UPDATE Events SET TournamentID='.$_POST['TournamentID'].',StartDate="'.$combineddate.'",GenderID='.$_POST['GenderID'].',DivisionID='.$_POST['DivisionID'].',TeamSize='.$_POST['TeamSize'].',NumberOfTeams='.$_POST['NumberOfTeams'].',Name="'.$_POST['Name'].'"  WHERE EventID='.$_GET['id'].';';
	$sendit_mod=mysqli_query($db,$SQLmod) or die(mysqli_error($db));
	die(header("Location: Events_viewall.php?tid=".$_GET['tid']));
} else {
	$SQLdet='SELECT * FROM Events WHERE EventID='.$_GET['id'].';';
	//print $SQLdet;
	$sendit_det=mysqli_query($db,$SQLdet) or die(mysqli_error($db));
	$RSdet=mysqli_fetch_object($sendit_det) or die(mysqli_error($db));
}

$thisYear=date("Y");
$years=1989;
$followingYears=$thisYear+3;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>daleclark.net</title>
<link type="text/css" rel="stylesheet" href="adminstyles.css" />
</head>
<body>
<div id="adminwrapper">
<div id="adminlogo"></div>
<?PHP navigation(); ?>
<div id="admincontent">
<h3>Modify or Delete Events</h3>
<p><a href="Events_viewall.php?tid=<?PHP print $_GET['tid']; ?>" style="font-size:10px; text-transform:uppercase;"><img src="../images/icon_back.png" style="border:none;" /> back to Events</a></p>
<form name="addForm" method="POST" action="Events_mod.php?tid=<?PHP print $_GET['tid']; ?>&id=<?PHP print $_GET['id']; ?>">
<input name="TournamentID" type="hidden" value="<?PHP print $RSdet->TournamentID; ?>" />
<?PHP list($year,$month,$day) = split("-",$RSdet->StartDate); ?>
<p><span class="label">Start Date</span><span class="inputbox">day: <select name="eventdate_day">
<option value="01"<?PHP if ($day=='01') { print ' selected'; } ?>>01</option>
<option value="02"<?PHP if ($day=='02') { print ' selected'; } ?>>02</option>
<option value="03"<?PHP if ($day=='03') { print ' selected'; } ?>>03</option>
<option value="04"<?PHP if ($day=='04') { print ' selected'; } ?>>04</option>
<option value="05"<?PHP if ($day=='05') { print ' selected'; } ?>>05</option>
<option value="06"<?PHP if ($day=='06') { print ' selected'; } ?>>06</option>
<option value="07"<?PHP if ($day=='07') { print ' selected'; } ?>>07</option>
<option value="08"<?PHP if ($day=='08') { print ' selected'; } ?>>08</option>
<option value="09"<?PHP if ($day=='09') { print ' selected'; } ?>>09</option>
<option value="10"<?PHP if ($day=='10') { print ' selected'; } ?>>10</option>
<option value="11"<?PHP if ($day=='11') { print ' selected'; } ?>>11</option>
<option value="12"<?PHP if ($day=='12') { print ' selected'; } ?>>12</option>
<option value="13"<?PHP if ($day=='13') { print ' selected'; } ?>>13</option>
<option value="14"<?PHP if ($day=='14') { print ' selected'; } ?>>14</option>
<option value="15"<?PHP if ($day=='15') { print ' selected'; } ?>>15</option>
<option value="16"<?PHP if ($day=='16') { print ' selected'; } ?>>16</option>
<option value="17"<?PHP if ($day=='17') { print ' selected'; } ?>>17</option>
<option value="18"<?PHP if ($day=='18') { print ' selected'; } ?>>18</option>
<option value="19"<?PHP if ($day=='19') { print ' selected'; } ?>>19</option>
<option value="20"<?PHP if ($day=='20') { print ' selected'; } ?>>20</option>
<option value="21"<?PHP if ($day=='21') { print ' selected'; } ?>>21</option>
<option value="22"<?PHP if ($day=='22') { print ' selected'; } ?>>22</option>
<option value="23"<?PHP if ($day=='23') { print ' selected'; } ?>>23</option>
<option value="24"<?PHP if ($day=='24') { print ' selected'; } ?>>24</option>
<option value="25"<?PHP if ($day=='25') { print ' selected'; } ?>>25</option>
<option value="26"<?PHP if ($day=='26') { print ' selected'; } ?>>26</option>
<option value="27"<?PHP if ($day=='27') { print ' selected'; } ?>>27</option>
<option value="28"<?PHP if ($day=='28') { print ' selected'; } ?>>28</option>
<option value="29"<?PHP if ($day=='29') { print ' selected'; } ?>>29</option>
<option value="30"<?PHP if ($day=='30') { print ' selected'; } ?>>30</option>
<option value="31"<?PHP if ($day=='31') { print ' selected'; } ?>>31</option>
</select>&nbsp;month: <select name="eventdate_month">
<option value="01"<?PHP if ($month=='01') { print ' selected'; } ?>>01</option>
<option value="02"<?PHP if ($month=='02') { print ' selected'; } ?>>02</option>
<option value="03"<?PHP if ($month=='03') { print ' selected'; } ?>>03</option>
<option value="04"<?PHP if ($month=='04') { print ' selected'; } ?>>04</option>
<option value="05"<?PHP if ($month=='05') { print ' selected'; } ?>>05</option>
<option value="06"<?PHP if ($month=='06') { print ' selected'; } ?>>06</option>
<option value="07"<?PHP if ($month=='07') { print ' selected'; } ?>>07</option>
<option value="08"<?PHP if ($month=='08') { print ' selected'; } ?>>08</option>
<option value="09"<?PHP if ($month=='09') { print ' selected'; } ?>>09</option>
<option value="10"<?PHP if ($month=='10') { print ' selected'; } ?>>10</option>
<option value="11"<?PHP if ($month=='11') { print ' selected'; } ?>>11</option>
<option value="12"<?PHP if ($month=='12') { print ' selected'; } ?>>12</option>
</select>&nbsp;year: <select name="eventdate_year">
<?PHP
while ($years<=$followingYears) {
	$years++;
	print '<option value="'.$years.'"';
	if ($years==$year) {
		print ' selected';
	}
	print '> '.$years.' </option>';
}
?>
</select></span></p>
<p><span class="label">Gender</span><span class="inputbox"><select name="GenderID">
<?PHP 
$SQLgg='SELECT * FROM Gender;';
$sendgg=mysqli_query($db,$SQLgg) or die(mysqli_error($db));
while ($RSgg=mysqli_fetch_object($sendgg)) {
	print '<option value="'.$RSgg->GenderID.'"';
	if ($RSdet->GenderID==$RSgg->GenderID) {
		print ' selected';
	}
	print '>'.$RSgg->Gender.'</option>';
}
?>
</select></span></p>
<p><span class="label">Division</span><span class="inputbox"><select name="DivisionID"></span></p>
<?PHP 
$SQLgd='SELECT * FROM Divisions;';
$sendgd=mysqli_query($db,$SQLgd) or die(mysqli_error($db));
while ($RSgd=mysqli_fetch_object($sendgd)) {
	print '<option value="'.$RSgd->DivisionID.'"';
	if ($RSdet->DivisionID==$RSgd->DivisionID) {
		print ' selected';
	}
	print '>'.$RSgd->Division.'</option>';
}
?>
</select></span></p>
<p><span class="label">Team Size</span><span class="inputbox"><select name="TeamSize">
<option value="2"<?PHP if ($RSdet->TeamSize==2) { print ' selected'; } ?>>2</option>
<option value="4"<?PHP if ($RSdet->TeamSize==4) { print ' selected'; } ?>>4</option>
</select></span></p>
<p><span class="label">Number Of Teams</span><span class="inputbox"><input name="NumberOfTeams" type="text" value="<?PHP print $RSdet->NumberOfTeams; ?>" /></span></p>
<p><span class="label">Name</span><span class="inputbox"><input name="Name" type="text" value="<?PHP print $RSdet->Name; ?>" /></span></p>
<p><input type="submit" value="modify" name="submit" /></p></form>
<p><a href="Events_del.php?id=<?PHP print $_GET['id']; ?>" class="deletelink">DELETE RECORD</a></p></div>
</div>
</body>
</html>
<?PHP
mysqli_close($db);
?>